<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@page import="cn.edu.nju.ws.sview.Config,java.util.Enumeration" %>
<%@page import="java.net.URLDecoder,cn.edu.nju.ws.sview.views.Group,cn.edu.nju.ws.sview.util.URIUtil,java.net.URLEncoder,cn.edu.nju.ws.sview.util.URIUtil,java.util.Enumeration,cn.edu.nju.ws.sview.views.Entity,java.util.HashMap,java.util.HashSet,java.util.ArrayList,java.util.Map.Entry,cn.edu.nju.ws.sview.cache.*" %>
<%@page import="cn.edu.nju.ws.sview.reasoning.Rule,cn.edu.nju.ws.sview.views.DataMember,cn.edu.nju.ws.sview.views.URIDataMember,cn.edu.nju.ws.sview.views.CustomDataMember" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>SView Query Item Editing</title>
<link rel="icon" href="/sview/favicon.ico" />
<link rel="stylesheet" type="text/css" href="/sview/css/bootstrap_button.min.css" />
<link rel="stylesheet" type="text/css" href="/sview/css/bootstrap_dropdown.min.css" />
<link rel="stylesheet" type="text/css" href="/sview/css/bootstrap_btn_group_dropdown.min.css" />
<link rel="stylesheet" type="text/css" href="/sview/css/layout.css" />
<link rel="stylesheet" type="text/css" href="/sview/css/smoothness/jquery-ui-1.8.16.custom.css" />
<link rel="stylesheet" type="text/css" href="/sview/css/views/dmedit.css" />
<link rel="stylesheet" type="text/css" href="/sview/css/easyui.css" />
<script type="text/javascript" src="/sview/script/jquery.js"></script>
<script type="text/javascript" src="/sview/script/bootstrap.min.js"></script>
<script type="text/javascript" src="/sview/script/jquery.easyui.min.js"></script>
<script type="text/javascript" src="/sview/script/jquery-ui-1.8.16.custom.min.js"></script>
<script type="text/javascript" src="/sview/script/global.js"></script>
<script type="text/javascript" src="/sview/script/views/dmedit.js"></script>
</head>
<body>
<%
	request.setCharacterEncoding("utf-8");
String lang = request.getParameter("lang");
if(lang!=null &&lang.equals("zh")){
	request.getRequestDispatcher("dmedit_zh.jsp").forward(request,response);
	return;
}else if(lang==null){
	lang="en" ;
}
String genre = request.getParameter("genre");
String eidStr =  request.getParameter("eid");
String dmidStr = request.getParameter("dmid");
String vtypeStr = request.getParameter("vtype");
String name =  request.getParameter("name");
if(name!=null)
	name = URLDecoder.decode(name,"utf-8");


int eid =0;
int etype=0;
int dmid= -1;
int vtype = 0;
String gname = (String)session.getAttribute("groupName");
if(genre==null||gname==null||dmidStr==null||vtypeStr==null){
	String location = "../views/index.jsp";
	if(lang.equals("zh"))
		location = location+"?lang="+lang;
	response.sendRedirect(location);
	return;
}else{
	eid = Integer.parseInt(eidStr);
	dmid = Integer.parseInt(dmidStr);
	vtype = Integer.parseInt(vtypeStr);
}
if(genre.equals(Entity.URI_ENTITY_Str))
	etype = Entity.URI_ENTITY;
else if(genre.equals(Entity.CUSTOM_ENTITY_Str))
		etype = Entity.CUSTOM_ENTITY;
else if(genre.equals(Entity.COLLECTION_Str))
	etype = Entity.COLLECTION;

/*view id >0 means enter from edit point*/
String vidStr = request.getParameter("vid");
int vid = 0;
if(vidStr!=null){
	vid = Integer.parseInt(vidStr) ;
}
if(dmid>0&&!CustomDataMember.isThere(dmid)){
	String location = "../views/index.jsp";
	if(lang.equals("zh"))
		location = location+"?lang="+lang;
	response.sendRedirect(location);
	return;
}
int gid = Group.getGroupIdByName(gname);
String isInnerStr = request.getParameter("i");
int isInner = Integer.parseInt(isInnerStr);
String cidStr = request.getParameter("cid");
int cid = Integer.parseInt(cidStr) ;
%>
<jsp:include page="/vheader.jsp" flush="true">
   <jsp:param name="f" value="e"/>
</jsp:include>
	<div class="container">
		<div class="top">
			<div class="operation">Construct a new query item</div>
			<div class="right">
				<a class="back" href="javascript:void()">Back to view editing</a>
				<input type="button" value="Save" class="save_op btn btn-primary fb disabled">
				<span class="more_op btn-group">
                   <button class="btn dropdown-toggle fb" data-toggle="dropdown" >More&nbsp;<span class="caret"></span></button>
                <ul class="dropdown-menu">
                  <li><a href="#" class="del_op">Delete</a></li>
                </ul>
                 </span>
            </div>
	    </div>
		<div class="mspacingLittle"></div>
		<div class="main">
		    <div class="mspacingMid"></div>
		    <div class="nameBox">
			   <span class="mtitle">Name</span>
			   <input type="text" class="ftext dmName" />
		    </div>
		    <div class="mspacingMid"></div>
		    <div class="mspacingTopLittle"></div>
		    <div class="ruleBox">
			   <div><span class="mtitle">Rules</span></div>
			   <div class="ruleList">
			   </div>
			    <div class="unsavedBox"><span class="mtitle unsaved">Unsaved rules</span></div>
			   <div class="tmpRuleList">
			   </div>
		    </div>
		    <div class="mspacingMid"></div>
		    <div class="mspacingBottomLittle"></div>
			<div class="mpanel">
			   <div class='hintTitle'>
		           Values
		           <span class='opHint'><span class="opStrong">Hint:</span> Assign values by Available Query Items<a class='closeHint'></a></span>
		       </div>
			   <div class="dmeditBox">
			   <div class="vcontent"></div>
			   </div>
			   <div class="rightPanel">
				<div class="vnav">
					<div class="dtitle">
						<span class="nav-title">Available Query Items</span>
					</div>
					<div class="search_tool">
				        <div class="myac-box qitem-box-inview">
			  	   			<div class="searchNote">Search a query item</div>
		           			<input class="myac-input dmsearch" type="text">
			    		</div>
			    		<div class ="searchBox"><ul id='vsresult' class='vsresult'></ul></div>
		      		</div>
					<div class="dms">
						<ul class="dmList">
						 <span class='hint_gray'>Try to search a query item and assign it to the current one</span>
						</ul>
					</div>
				</div>
			   </div>
			</div>
		</div>
	</div>
<input type='hidden' name="display-lang" id="display-lang" value="en" />
<input type='hidden'  id="count" value="0" />
<input type='hidden' id="etype" value=<%=etype %> />
<input type='hidden' id="genre" value=<%=genre %> />
<input type='hidden'  id="eid" value=<%=eid %> />
<input type='hidden' id="vlayout" value=1 />
<input type='hidden'  id="gid" value=<%=gid%> />
<input type='hidden'  id="vid" value=<%=vid%> />
<input type='hidden'  id="isInner" value=<%=isInner%> />
<input type='hidden'  id="cid" value=<%=cid%> />
<input type='hidden'  id="dmid" value=<%=dmid%> />
<input type='hidden'  id="vtype" value=<%=vtype%> />
<%if(name!=null) {
%>
<input type='hidden'  id="name" value="<%=name%>" />
<%} %>
<div class="hidden history">
</div>
  <div class="warning">
	   <div class="warnBox">
	    <p>
	       Are you sure to delete this query item (Caution: deletion is unrecoverable)?
	    </p>
	   </div>
	</div>
  <div class="warning rule">
	   <div class="warnBox">
	    <p>
	       Are you sure to delete the rule(Caution: deletion is unrecoverable)?
	    </p>
	   </div>
	</div>	
<jsp:include page="/vfooter.jsp"></jsp:include>
</body>
</html>